import 'dart:convert';

import 'package:android_intent_plus/android_intent.dart';
import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_fai_webview/flutter_fai_webview.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sph_shipper/AppConfig/Config.dart';
import 'package:sph_shipper/Order/WaybillDetails/ModifyTransportationAgreement.dart';
import 'package:sph_shipper/http/NoLoadingGetApi.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../AppConfig/LocalStorage.dart';
import '../../AppConfig/RouteAct.dart';
import '../../AppConfig/ShowDialog.dart';
import '../../TabBar/TabbarView.dart';
import '../../http/api.dart';
import 'package:platform/platform.dart';
class ConfirmedTransportationAgreement extends StatefulWidget {
  const ConfirmedTransportationAgreement({super.key, required this.wayllBillId,});
  final String wayllBillId;
  @override
  State<ConfirmedTransportationAgreement> createState() => _ConfirmedTransportationAgreementState();
}

class _ConfirmedTransportationAgreementState extends State<ConfirmedTransportationAgreement> {
  @override
  int personType=1;
  Map dataMap={};
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getContractAct();

  }
  void getContractAct(){
    print(widget.wayllBillId);
    NoLoadinggetApiManager.getData(
      context,
      "api/waybill/contract/detail",
      {"id":widget.wayllBillId,},
          (responseData)  {
        setState(() {
         dataMap=responseData['data'];
 
        });
      },
    );
  }
  _makePhoneCall(String phoneNumber) async {
    if (LocalPlatform().isAndroid) {
      var status = await Permission.phone.status;
      if (status.isGranted) {
        // 权限已被授予
        // callPhone();
        final AndroidIntent intent = AndroidIntent(
          action: 'android.intent.action.CALL',
          data: Uri.encodeFull('tel:$phoneNumber'),
        );
        await intent.launch();
      } else if (status.isDenied) {
        // 权限被拒绝，但用户可以再次授权
        showCallPhoneFirstDialog(context);
        status = await Permission.phone.request();
        if (status.isGranted) {
          // 用户同意了权限
          // callPhone();
          final AndroidIntent intent = AndroidIntent(
            action: 'android.intent.action.CALL',
            data: Uri.encodeFull('tel:$phoneNumber'),
          );
          await intent.launch();
        } else {
          showCallPhoneDialog(context);
          // 用户拒绝权限，无法发起电话
          // 可以在此处展示信息提示用户需要权限
        }
      } else if (status.isPermanentlyDenied) {
        // 权限被永久拒绝，需要用户手动开启权限
        showCallPhoneDialog(context);
      }

    }else{
      final url =Uri.parse('tel:$phoneNumber');
      if (await canLaunchUrl(url)) {
        await launchUrl(url);
      } else {
        throw '无法拨打电话：$url';
      }
    }
  }
  Future<void> refuseEditContract(int status) async {


  }
  Future<void> sureEditWaybillContract() async {

  }
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
    backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        leading: IconButton(
          onPressed: () {
            Navigator.pop(context);
          },
          icon: Icon(Icons.arrow_back_ios),
        ),
        title: Text("货物运输协议",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
        actions: [
          GestureDetector(
            child: Text("联系司机",style: TextStyle(color: Colors.black),),
            onTap: (){
              _makePhoneCall(dataMap['contractInfo']['driverInfo']['phoneNum']);
            },
          ),
        ],
      ),
      body:dataMap.isEmpty?Container(): Column(
        children: [
          Expanded(
              child: ListView(
            children: [
              Container(
                margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                padding: EdgeInsets.only(left: 8.w,right: 6.w,top: 8.h,bottom: 8.h),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Image.asset("lib/Images/OrderList/货物运输协议单据icon.png",width: 42.w,height: 40.h,),
                            Column(
                              children: [
                                Image.asset("lib/Images/OrderList/装icon.png",width:15.w ,height:15.h,),
                                Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:12.h,),
                                if(dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'].length==2)
                                  Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      Image.asset("lib/Images/OrderList/装icon.png",width:15.w ,height:15.h,),
                                      Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:12.h,),
                                    ],
                                  ), 
                                if(dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'].length==2)
                                  Column(
                                    children: [
                                      Image.asset("lib/Images/OrderList/卸icon.png",width:15.w ,height:15.h,),
                                      Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:12.h,),
                                    ],
                                  ),
                                Image.asset("lib/Images/OrderList/卸icon.png",width:15.w ,height:15.h,),
                              ],
                            ),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [

                                Row(
                                  children: [
                                    Container(
                                      constraints: BoxConstraints(
                                        maxWidth:170.w, // 限制文本最大宽度
                                      ),
                                      child:
                                      Text(dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'][0]['city']+" "+dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,overflow: TextOverflow.ellipsis,fontSize: 14.sp,fontWeight: FontWeight.w600),),
                                    ),

                                  ],
                                ),
                                if(dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'].length==2)
                                  Column(
                                    children: [
                                      SizedBox(height: 10.h,),
                                      Container(
                                        constraints: BoxConstraints(
                                          maxWidth:170.w, // 限制文本最大宽度
                                        ),
                                        child:Text(dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'][1]['city']+" "+dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'][1]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp,fontWeight: FontWeight.w600),overflow: TextOverflow.ellipsis,),

                                      ),

                                    ],
                                  ),
                                SizedBox(height:10.h,),
                                if(dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'].length==2)
                                  Column(
                                    children: [
                                      Container(
                                        constraints: BoxConstraints(
                                          maxWidth:170.w, // 限制文本最大宽度
                                        ),
                                        child: Text(dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][0]['city']+" "+dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp,fontWeight: FontWeight.w600),overflow: TextOverflow.ellipsis,),

                                      ),


                                      SizedBox(height:10.h,),
                                    ],
                                  ),
                                Row(
                                  children:[
                                    dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'].length==2?
                                    Container(
                                        constraints: BoxConstraints(
                                          maxWidth:170.w, // 限制文本最大宽度
                                        ),
                                        child: Text(dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][1]['city']+" "+dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][1]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp,fontWeight: FontWeight.w600),overflow: TextOverflow.ellipsis,)
                                    )
                                        :
                                    Container(
                                      constraints: BoxConstraints(
                                        maxWidth:170.w, // 限制文本最大宽度
                                      ),
                                      child:  Text(dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][0]['city']+" "+dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp,fontWeight: FontWeight.w600),overflow: TextOverflow.ellipsis,),
                                    ),

                                  ],
                                ),


                              ],
                            ),
                            // Column(
                            //   crossAxisAlignment: CrossAxisAlignment.start,
                            //   children: [
                            //     Container(
                            //       width: 200.w,
                            //       child: Text(dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'][0]['city']+dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'][0]['county']+"-"+dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][0]['city']+dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600),),
                            //
                            //     ),
                            //     Text("运单编号:"+dataMap['waybillId'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            //   ],
                            // ),
                          ],
                        ),
                        if(dataMap['effectiveness']==1&&(dataMap['status']==0||dataMap['status']==1))
                          Image.asset("lib/Images/OrderList/运输协议签约成功icon.png",width: 50.w,height: 50.h,),
                        if(dataMap['effectiveness']==-1&&(dataMap['status']==1||dataMap['status']==0))
                          Image.asset("lib/Images/OrderList/签约失败@3x.png",width: 50.w,height: 50.h,),
                        if(dataMap['effectiveness']==0&&dataMap['status']==0)
                          Image.asset("lib/Images/OrderList/待签署@3x.png",width: 50.w,height: 50.h,),
                      ],
                    ),
                    Text("运单编号:"+dataMap['waybillId'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                  ],
                ),
              ),
              Container(
                margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                padding: EdgeInsets.only(left: 10.w,right:10.w,top: 10.h,bottom: 10.h),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    if(dataMap['contractInfo']['depositType']!=-1)
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Text("订金",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                            Text(dataMap['contractInfo']['depositType']==0?"(退还)":"(不退还)",style: TextStyle(color: Colors.black),),
                          ],
                        ),
                        Text((dataMap['contractInfo']['deposit']).toString()+"元",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                      ],
                    ),
                    if(dataMap['contractInfo']['depositType']!=-1)
                    SizedBox(height: 8.h,),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("运费",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        Text((dataMap['contractInfo']['freight']).toString()+"元",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                      ],
                    ),
                    SizedBox(height: 8.h,),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("付款周期",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        if(dataMap['contractInfo']['payPeriod']<366)
                          Text("货到"+dataMap['contract']['contractInfo']['payPeriod'].toString()+"天后付",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        if(dataMap['contractInfo']['payPeriod']==801)
                          Text("货到付",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        if(dataMap['contractInfo']['payPeriod']==802)
                          Text("回单付",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        if(dataMap['contractInfo']['payPeriod']==830)
                          Text("月结",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        if(dataMap['contractInfo']['payPeriod']==890)
                          Text("季结",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        if(dataMap['contractInfo']['payPeriod']==980)
                          Text("半年结",style: TextStyle(color: Colors.black,fontSize: 14.sp),),

                      ],
                    ),
                    // Divider(height: 16.h,color: MyColors.backgreyColor,),
                    // Text("普票服务费",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 18.sp),),
                    // SizedBox(height: 6.h,),
                    // Row(
                    //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    //   children: [
                    //     Row(
                    //       children: [
                    //         Text("电子协议费",style: TextStyle(color: Colors.black),),
                    //         GestureDetector(
                    //           child: Icon(Icons.help_outline,color: MyColors.hintColor,size: 18,),
                    //           onTap: (){
                    //             showModalBottomSheet(
                    //                 context: context,
                    //                 isScrollControlled: true,
                    //
                    //                 builder: (BuildContext context) {
                    //                   return bottomSheet( sheetType: 1,
                    //
                    //                   );
                    //                 }
                    //             );
                    //           },
                    //         ),
                    //       ],
                    //     ),
                    //     Text((dataMap['elecProtocolCharge']).toString()+"元",style: TextStyle(color: Colors.black),),
                    //   ],
                    // ),
                    // SizedBox(height: 6.h,),
                    // Row(
                    //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    //   children: [
                    //     Row(
                    //       children: [
                    //         Text("轨迹校验费",style: TextStyle(color: Colors.black),),
                    //         GestureDetector(
                    //           child: Icon(Icons.help_outline,color: MyColors.hintColor,size: 18,),
                    //           onTap: (){
                    //             showModalBottomSheet(
                    //                 context: context,
                    //                 isScrollControlled: true,
                    //
                    //                 builder: (BuildContext context) {
                    //                   return bottomSheet( sheetType: 2,
                    //
                    //                   );
                    //                 }
                    //             );
                    //           },
                    //         ),
                    //       ],
                    //     ),
                    //     Text((dataMap['trajectoryVerificationCharge']).toString()+"元",style: TextStyle(color: Colors.black),),
                    //   ],
                    // ),
                    // SizedBox(height: 6.h,),
                    // Row(
                    //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    //   children: [
                    //     Row(
                    //       children: [
                    //         Text("技术服务费",style: TextStyle(color: Colors.black),),
                    //         GestureDetector(
                    //           child: Icon(Icons.help_outline,color: MyColors.hintColor,size: 18,),
                    //           onTap: (){
                    //             showModalBottomSheet(
                    //                 context: context,
                    //                 isScrollControlled: true,
                    //
                    //                 builder: (BuildContext context) {
                    //                   return bottomSheet( sheetType: 3,
                    //
                    //                   );
                    //                 }
                    //             );
                    //           },
                    //         ),
                    //       ],
                    //     ),
                    //     Text((dataMap['techServiceCharge']).toString()+"元",style: TextStyle(color: Colors.black),),
                    //   ],
                    // ),
                    // SizedBox(height: 12.h,),
                    // Row(
                    //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    //   children: [
                    //     Row(
                    //       children: [
                    //         Text("总费用",style: TextStyle(color: Colors.black,fontSize: 18.sp,fontWeight: FontWeight.w600),),
                    //         Text("（不包含订金）",style: TextStyle(color: MyColors.textColor),),
                    //         GestureDetector(
                    //           child: Icon(Icons.help_outline,color: MyColors.hintColor,size: 18,),
                    //           onTap: (){
                    //             showModalBottomSheet(
                    //                 context: context,
                    //                 isScrollControlled: true,
                    //
                    //                 builder: (BuildContext context) {
                    //                   return bottomSheet( sheetType: 4,
                    //
                    //                   );
                    //                 }
                    //             );
                    //           },
                    //         ),
                    //       ],
                    //     ),
                    //     Text((dataMap['alreadyAmount']).toString()+"元",style: TextStyle(color: MyColors.themeColor),),
                    //   ],
                    // ),

                  ],
                ),
              ),
              Container(
                margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                padding: EdgeInsets.only(left: 7.w,right:8.w,top: 16.h,bottom: 20.h),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                ),
                child: Column(
                  children: [
                    // Row(
                    //   children: [
                    //     Text("运费单价",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                    //     SizedBox(width: 50.w,),
                    //     Text("60元/吨",style: TextStyle(fontSize: 13.sp,color:Colors.black),),
                    //   ],
                    // ),
                    // SizedBox(height: 8.h,),
                    Row(
                      children: [
                        Text("货物信息",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                        SizedBox(width: 50.w,),
                        Container(
                          width: screenSize.width-200.w,
                          child:
                          Row(
                            children: [

                              RichText(
                                text:TextSpan(children: [
                                  if(dataMap['contractInfo']['goodsInfo']['cargoInfo'][0]['cargoName']!=null)
                                    TextSpan(
                                        text: dataMap['contractInfo']['goodsInfo']['cargoInfo'][0]['cargoName'],
                                        style: TextStyle(fontSize: 13.sp, color:Colors.black)),
                                  if(dataMap['contractInfo']['goodsInfo']['cargoInfo'][0]['packageType']!=null)
                                    TextSpan(
                                        text: dataMap['contractInfo']['goodsInfo']['cargoInfo'][0]['packageType'],
                                        style: TextStyle(fontSize: 13.sp, color:Colors.black)),
                                  if(dataMap['contractInfo']['goodsInfo']['cargoInfo'][0]['cargoWeight']!=0)
                                    TextSpan(
                                        text: dataMap['contractInfo']['goodsInfo']['cargoInfo'][0]['cargoWeight'].toString()+"吨",
                                        style: TextStyle(fontSize: 13.sp, color:Colors.black)),
                                  if(dataMap['contractInfo']['goodsInfo']['cargoInfo'][0]['cargoVolume']!=0)
                                    TextSpan(
                                        text: dataMap['contractInfo']['goodsInfo']['cargoInfo'][0]['cargoVolume'].toString()+"方",
                                        style: TextStyle(fontSize: 13.sp, color:Colors.black)),
                                ],
                                ),
                              ),
                            ],
                          ),
                        )
]
                    ),
                    SizedBox(height: 8.h,),
                    Row(
                      children: [
                        Text("车长车型",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                        SizedBox(width: 50.w,),
                        Text(dataMap['contractInfo']['vehicleInfo']['vehicleLength']+"米/"+dataMap['contractInfo']['vehicleInfo']['vehicleModel'],style: TextStyle(fontSize: 13.sp,color:Colors.black),),
                      ],
                    ),
                    SizedBox(height: 8.h,),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text("装货时间",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                        SizedBox(width: 50.w,),
                        Container(
                          width: screenSize.width-220.w,
                          child: Text(dataMap['contractInfo']['goodsInfo']['loadDay']+" "+dataMap['contractInfo']['goodsInfo']['loadTime']+"点装货",style: TextStyle(fontSize: 13.sp,color:Colors.black),),
                        ),
                      ],
                    ),
                    SizedBox(height: 8.h,),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text("装货地址",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                        SizedBox(width: 50.w,),
                        Container(
                          width: screenSize.width-140.w,
                          child:    Text(dataMap['contractInfo']['goodsInfo']['loadPlaceInfo'][0]['address'],style: TextStyle(fontSize: 13.sp,color:Colors.black),),
                        ),
                      ],
                    ),
                    SizedBox(height: 8.h,),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text("卸货时间",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                        SizedBox(width: 50.w,),
                        Container(
                          width: screenSize.width-220.w,
                          child:Text(dataMap['contractInfo']['goodsInfo']['unloadDay']==null?"未约定，如需约定请修改协议":dataMap['contractInfo']['goodsInfo']['unloadDay']+" "+dataMap['contractInfo']['goodsInfo']['unloadTime']+"点卸货",style: TextStyle(fontSize: 13.sp,color:dataMap['contractInfo']['goodsInfo']['unloadDay']==null?MyColors.themeColor:Colors.black),),

                        ),
                      ],
                    ),
                    SizedBox(height: 8.h,),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text("卸货地址",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                        SizedBox(width: 50.w,),
                        Container(
                          width: screenSize.width-140.w,
                          child:    Text(dataMap['contractInfo']['goodsInfo']['unloadPlaceInfo'][0]['address'],style: TextStyle(fontSize: 13.sp,color:Colors.black),),
                        ),

                      ],
                    ),
                    // Row(
                    //   children: [
                    //     Text("付款时间",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                    //     SizedBox(width: 50.w,),
                    //     RichText(
                    //       text: TextSpan(
                    //         text: '最晚卸货后',
                    //         style: TextStyle(fontSize: 13.sp, color: Colors.black),
                    //         children: <TextSpan>[
                    //           TextSpan(
                    //             text: dataMap['payFreightTime'],
                    //             style: TextStyle(
                    //               color: MyColors.themeColor, // 设置为黄色
                    //               fontWeight: FontWeight.bold, // 可根据需要添加其他样式
                    //             ),
                    //           ),
                    //           TextSpan(
                    //             text: '天内付运费',
                    //             style: TextStyle(fontSize: 13.sp, color: Colors.black),
                    //           ),
                    //         ],
                    //       ),
                    //     )
                    //   ],
                    // ),
                    SizedBox(height: 8.h,),
                    Row(
                      children: [
                        Text("其他"+"       ",style: TextStyle(fontSize: 13.sp,color: MyColors.textColor),),
                        SizedBox(width: 50.w,),
                        Text(dataMap['contractInfo']['remark']==null?"":dataMap['contractInfo']['remark'],style: TextStyle(fontSize: 13.sp,color:Colors.black),),
                      ],
                    ),
                  ],
                ),
              ),
              Container(
                margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                padding: EdgeInsets.only(left: 7.w,right:23.w,top: 10.h,bottom: 15.h),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                ),
                child: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        SizedBox(),
                        GestureDetector(
                          child: Column(
                            children: [
                              Text("托运人",style: TextStyle(color: Colors.black,fontWeight:personType==1?FontWeight.w600:FontWeight.w300 ,fontSize: 13.sp),),
                              SizedBox(height: 8.h,),
                              Container(width: 20.w,height: 3.h,color: personType==1?MyColors.themeColor:Colors.white,),
                            ],
                          ),
                          onTap: (){
                            setState(() {
                              personType=1;
                            });
                          },
                        ),
                      if(dataMap['contractInfo']['type']=="WLHY")
                        GestureDetector(
                          child: Column(
                            children: [
                              Text("承运人",style: TextStyle(color: Colors.black,fontWeight:personType==2?FontWeight.w600:FontWeight.w300,fontSize: 13.sp ),),
                              SizedBox(height: 8.h,),
                              Container(width: 20.w,height: 3.h,color: personType==2?MyColors.themeColor:Colors.white,),
                            ],
                          ),
                          onTap: (){
                            setState(() {
                              personType=2;
                            });
                          },
                        ),
                        GestureDetector(
                          child: Column(
                            children: [
                              Text(dataMap['contractInfo']['type']=="WLHY"?"实际承运人":"承运人",style: TextStyle(color: Colors.black,fontWeight:personType==3?FontWeight.w600:FontWeight.w300,fontSize: 13.sp ),),
                              SizedBox(height: 8.h,),
                              Container(width: 20.w,height: 3.h,color: personType==3?MyColors.themeColor:Colors.white,),
                            ],
                          ),
                          onTap: (){
                            setState(() {
                              personType=3;
                            });
                          },
                        ),
                        SizedBox(),
                      ],
                    ),
                    SizedBox(height: 19.h,),
                    personType==1?
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text("姓名",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                SizedBox(height: 8.h,),
                                Text("联系电话",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                // SizedBox(height: 8.h,),
                                // Text("确认时间",style: TextStyle(color: MyColors.textColor),),
                              ],
                            ),
                            SizedBox(width: 19.h,),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(dataMap['contractInfo']['shipperInfo']['realName'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                SizedBox(height: 8.h,),
                                Text(dataMap['contractInfo']['shipperInfo']['phoneNum'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                // SizedBox(height: 8.h,),
                                // if(dataMap['shprSureTime']!=null)
                                // Text(dataMap['shprSureTime'],style: TextStyle(color: Colors.black),),
                              ],
                            ),

                          ],
                        ),
                        Image.network( MyServiceUrl.imgHeader+dataMap['contractInfo']['shipperInfo']['avatarPath'],
                          width: 40.w,height: 40.h,),
                      ],
                    ):personType==2?
                    Text(dataMap['contractInfo']['haulierInfo']['name'],style: TextStyle(color: Colors.black),)
                        : Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text("姓名",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                SizedBox(height: 8.h,),
                                Text("联系电话",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                SizedBox(height: 8.h,),
                                Text("车牌号",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                // SizedBox(height: 8.h,),
                                // Text("确认时间",style: TextStyle(color: MyColors.textColor),),
                              ],
                            ),
                            SizedBox(width: 19.h,),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(dataMap['contractInfo']['driverInfo']['realName'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                SizedBox(height: 8.h,),
                                Text(dataMap['contractInfo']['driverInfo']['phoneNum'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                SizedBox(height: 8.h,),
                                Text(dataMap['contractInfo']['vehicleInfo']['vehicleNum'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                // SizedBox(height: 8.h,),
                                // Text(dataMap['drvSureTime'],style: TextStyle(color: Colors.black),),
                              ],
                            ),

                          ],
                        ),
                        Image.network(MyServiceUrl.imgHeader+dataMap['contractInfo']['driverInfo']['avatarPath'],
                          width: 40.w,height: 40.h,),
                      ],
                    ),
                  ],
                ),
              ),
              SizedBox(height: 8.h,),
              Center(
                child: Text("货物运输协议",style: TextStyle(color: Colors.black,fontSize: 18.sp,fontWeight: FontWeight.w600),),
              ),
              Container(
               height: 300.h,
                margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                ),
                child: InAppWebView(
                  initialUrlRequest: URLRequest(url: Uri.parse('http://oss.sph56.cn/sph56/waybill/1745690061430661121/load/b0c9fc919e9042a39c4d96e164ad1e45.pdf')),
                  onWebViewCreated: (InAppWebViewController controller) {
                    controller.setOptions(
                      options: InAppWebViewGroupOptions(
                        android: AndroidInAppWebViewOptions(
                          useWideViewPort: true,
                          supportMultipleWindows: true,
                        ),
                        ios: IOSInAppWebViewOptions(
                          allowsBackForwardNavigationGestures: true,
                        ),
                      ),
                    );
                  },
                ),
                
              ),
            ],
              ),
          ),
          // if(dataMap['status']==1)
            Container(
              height: 80.h,
              color: Colors.white,
              padding: EdgeInsets.only(left: 15.w,right: 15.w,top:10.h,bottom: 40.h ),
              child: BrnSmallMainButton(
                title: '修改协议',
                bgColor:MyColors.themeColor,
                radius: 30,
                fontSize: 14.sp,
                width: screenSize.width-30.w,
                onTap: () {
                  Navigator.push( context, FadeRoute(page:ModifyTransportationAgreement(dataMap:{"contract":dataMap} ,)));
                },
              ),
            ),
        ],
      ),

    );
  }
}

class bottomSheet extends StatefulWidget {
  const bottomSheet({super.key, required this.sheetType});
  final int sheetType;
  @override
  State<bottomSheet> createState() => _bottomSheetState();
}

class _bottomSheetState extends State<bottomSheet> {
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Container(
      padding: EdgeInsets.only(left: 17.w,top: 12.h,right: 11.w),
      height: 185.h,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(10)),
      ),
      child: Column(
        children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(width: 30.w,),
                Text(widget.sheetType==1?"电子协议费":widget.sheetType==2?"轨迹校验费":widget.sheetType==3?"技术服务费":"总费用",
                  style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600),),
                GestureDetector(
                  child: Icon(Icons.close,color: MyColors.authTipColor,size: 30,),
                  onTap: (){
                    Navigator.pop(context);
                  },
                ),
              ],
            ),
          SizedBox(height: 8.h,),
          widget.sheetType==1?
          Container(
            width: screenSize.width-34.w,
            child: Text("您与司机在线签署协议后，平台会为您和司机生成含有效电子签名的电子协议，能够更好的保护您的各项权益，产生纠纷后也可以作为有效凭证。电子协议可以在订单详情中进行查看和下载。",
            style: TextStyle(color: Colors.black),),
          ):widget.sheetType==2?
          Container(
            width: screenSize.width-34.w,
            child: Text("为了保证订单的真实性，平台会全程收集司机及车辆的定位信息并进行轨迹校验，订单完成后您可以在订单详情中查看司机运输轨迹及订单进度、状态。",
              style: TextStyle(color: Colors.black),),
          ):widget.sheetType==3?
          Container(
            width: screenSize.width-34.w,
            child: Text("技术服务费率1%，例: 运费1000元，则技术服务费为10元",
              style: TextStyle(color: Colors.black),),
          )
          : Container(
            width: screenSize.width-34.w,
            child: Text("不包含订金\n包含运费、油卡金额、服务费金额",
              style: TextStyle(color: Colors.black),),
          )
            ],
      ),
    );
  }
}
